﻿using System;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Text;

namespace IService.Utility
{
	public static class CommUtil
	{

		public static string CreateHtmlBody(string htmlFile, params object[] objs)
		{
			string rawHtml = GetHtmlFromResource(htmlFile);
			return String.Format(CultureInfo.InvariantCulture, rawHtml, objs);
		}

		private static string GetHtmlFromResource(string htmlFile)
		{
			using (Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream(
			   "IService.MailHtml." + htmlFile))
			{
				byte[] buffer = new byte[s.Length];
				s.Position = 0;
				s.Read(buffer, 0, (int)s.Length);
				return Encoding.UTF8.GetString(buffer);
			}
		}
	}
}